using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using Model;

public partial class Join : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["uid"] == null)
                Response.Redirect("auth.aspx");
            ViewState["IID"] = Request.QueryString["IID"].ToString();
            ViewState["uid"] = Session["uid"];
            ViewState["PreURL"] = null;
            ViewState["PreURL"] = Request.UrlReferrer.ToString();
            ViewState["i"] = Request.QueryString["i"];
        }
    }

    protected void Lbtn_Click(object sender, EventArgs e)
    {
        int i = int.Parse(Request.QueryString["i"]);
        string path = "";
        switch (i)
        {
            case 0:
                path = "Hot.aspx";
                break;
            case 1:
                path = "Latest.aspx";
                break;
            case 2:
                path = "My.aspx";
                break;
            case 3:
                path = "Favorite.aspx";
                break;
        }
        Response.Redirect(path);
    }

    protected void Ibtn_Click(object sender, ImageClickEventArgs e)
    {
        int i = int.Parse(Request.QueryString["i"]);
        string path = "";
        switch (i)
        {
            case 0:
                path = "Hot.aspx";
                break;
            case 1:
                path = "Latest.aspx";
                break;
            case 2:
                path = "My.aspx";
                break;
            case 3:
                path = "Favorite.aspx";
                break;
        }
        Response.Redirect(path);
    }

    protected void Image1_ServerClick(object sender, ImageClickEventArgs e)
    {
        ReasonService rsc = new ReasonService();
        Reason reason = new Reason();
        reason.IID = int.Parse(ViewState["IID"].ToString());
        reason.UID = ViewState["uid"].ToString();
        string hour = System.DateTime.Now.Hour > 9 ? System.DateTime.Now.Hour.ToString() : "0" + System.DateTime.Now.Hour;
        string min = System.DateTime.Now.Minute > 9 ? System.DateTime.Now.Minute.ToString() : "0" + System.DateTime.Now.Minute;
        string sec = System.DateTime.Now.Second > 9 ? System.DateTime.Now.Second.ToString() : "0" + System.DateTime.Now.Second;
        reason.Time = System.DateTime.Now.ToString("yyyy-MM-dd") + " " + hour + ":" + min + ":" + sec;
        reason.Content = Content.InnerText;

        int result = rsc.CreateReason(reason);

        if (result == 1)
        {
            //send email
            string subject = "test";
            string body = "test";
            //Utilities.SendMail(Email.Text, subject, body);
        }
        else
        {
            //Response.Write("<script type='text/javascript'> alert('You have already joined.');</script>");
        }
        int i = int.Parse(ViewState["i"].ToString());
        string path = "";
        switch (i)
        {
            case 0:
                path = "Hot.aspx";
                break;
            case 1:
                path = "Latest.aspx";
                break;
            case 2:
                path = "My.aspx";
                break;
            case 3:
                path = "Favorite.aspx";
                break;
        }
        Response.Redirect("ResponsePage.aspx?type=2&path=" + path);
    }
}
